home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / • Extras • / SGI STL / multiset.h < prev    next >
C/C++ Source or Header  |  1997-05-28  |  8KB  |  230 lines

  1. /*
  2.  *
  3.  * Copyright (c) 1994
  4.  * Hewlett-Packard Company
  5.  *
  6.  * Permission to use, copy, modify, distribute and sell this software
  7.  * and its documentation for any purpose is hereby granted without fee,
  8.  * provided that the above copyright notice appear in all copies and
  9.  * that both that copyright notice and this permission notice appear
  10.  * in supporting documentation.  Hewlett-Packard Company makes no
  11.  * representations about the suitability of this software for any
  12.  * purpose.  It is provided "as is" without express or implied warranty.
  13.  *
  14.  *
  15.  * Copyright (c) 1996
  16.  * Silicon Graphics Computer Systems, Inc.
  17.  *
  18.  * Permission to use, copy, modify, distribute and sell this software
  19.  * and its documentation for any purpose is hereby granted without fee,
  20.  * provided that the above copyright notice appear in all copies and
  21.  * that both that copyright notice and this permission notice appear
  22.  * in supporting documentation.  Silicon Graphics makes no
  23.  * representations about the suitability of this software for any
  24.  * purpose.  It is provided "as is" without express or implied warranty.
  25.  *
  26.  * Copyright (c) 1997
  27.  * Moscow Center for SPARC Technology
  28.  *
  29.  * Permission to use, copy, modify, distribute and sell this software
  30.  * and its documentation for any purpose is hereby granted without fee,
  31.  * provided that the above copyright notice appear in all copies and
  32.  * that both that copyright notice and this permission notice appear
  33.  * in supporting documentation.  Moscow Center for SPARC Technology makes no
  34.  * representations about the suitability of this software for any
  35.  * purpose.  It is provided "as is" without express or implied warranty.
  36.  *
  37.  */
  38.  
  39. #ifndef __SGI_STL_MULTISET_H
  40. #define __SGI_STL_MULTISET_H
  41.  
  42. # ifndef __SGI_STL_TREE_H
  43. #  include <tree.h>
  44. # endif
  45.  
  46. __BEGIN_STL_NAMESPACE
  47. __BEGIN_STL_FULL_NAMESPACE
  48. #define multiset __WORKAROUND_RENAME(multiset)
  49.  
  50. template <class Key, __DFL_TMPL_PARAM(Compare,less<Key>), 
  51.                      __DFL_TYPE_PARAM(Alloc,alloc) >
  52. class multiset {
  53.     typedef multiset<Key,Compare,Alloc> self;
  54. public:
  55. // typedefs:
  56.     typedef Key key_type;
  57.     typedef Key value_type;
  58.     typedef Compare key_compare;
  59.     typedef Compare value_compare;
  60.     typedef rb_tree<key_type, value_type, 
  61.                     identity<value_type>, 
  62.                     key_compare, Alloc>        rep_type;
  63.     typedef typename rep_type::const_pointer   pointer;
  64.     typedef typename rep_type::const_reference reference;
  65.     typedef typename rep_type::const_reference const_reference;
  66.     typedef typename rep_type::const_iterator  const_iterator;
  67.     // SunPro bug
  68. #  ifdef __SUNPRO_CC  
  69.     typedef const_iterator iterator;
  70. #  else
  71.     typedef typename rep_type::const_iterator iterator;
  72. #  endif
  73.     typedef typename rep_type::const_reverse_iterator reverse_iterator;
  74.     typedef typename rep_type::const_reverse_iterator const_reverse_iterator;
  75.     typedef typename rep_type::size_type size_type;
  76.     typedef typename rep_type::difference_type difference_type;
  77.  
  78. private:
  79.     rep_type t;  // red-black tree representing multiset
  80.  
  81. // allocation/deallocation
  82. public:
  83.     multiset() : t(Compare()) {}
  84.     explicit multiset(const Compare& comp) : t(comp) {}
  85.     multiset(const value_type* first, const value_type* last) : 
  86.         t(Compare()) {
  87.                t.insert_equal(first, last);
  88.     }
  89.     multiset(const value_type* first, const value_type* last, 
  90.              const Compare& comp) : t(comp) {
  91.                t.insert_equal(first, last);
  92.     }
  93.     multiset(const_iterator first, const_iterator last ) : t(Compare()) {
  94.                t.insert_equal(first, last);
  95.     }
  96.     multiset(const_iterator first, const_iterator last, 
  97.              const Compare& comp) : t(comp) {
  98.                t.insert_equal(first, last);
  99.     }
  100.     multiset(const self& x) : t(x.t) {}
  101.     self& operator=(const self& x) {
  102.         t = x.t; 
  103.         return *this;
  104.     }
  105.  
  106. // accessors:
  107.  
  108.     key_compare key_comp() const { return t.key_comp(); }
  109.     value_compare value_comp() const { return t.key_comp(); }
  110.     iterator begin() const { return t.begin(); }
  111.     iterator end() const { return t.end(); }
  112.     reverse_iterator rbegin() const { return t.rbegin(); } 
  113.     reverse_iterator rend() const { return t.rend(); }
  114.     bool empty() const { return t.empty(); }
  115.     size_type size() const { return t.size(); }
  116.     size_type max_size() const { return t.max_size(); }
  117.     void swap(self& x) { t.swap(x.t); }
  118.  
  119. // insert/erase
  120.     iterator insert(const value_type& x) { 
  121.       return t.insert_equal(x);
  122.     }
  123.     iterator insert(iterator position, const value_type& x) {
  124.       return t.insert_equal((typename rep_type::iterator&)position, x);
  125.     }
  126.     void insert(const value_type* first, const value_type* last) {
  127.       t.insert_equal(first, last);
  128.     }
  129.     void insert(const_iterator first, const_iterator last) {
  130.       t.insert_equal(first, last);
  131.     }
  132.     void erase(iterator position) { 
  133.         t.erase((typename rep_type::iterator&)position); 
  134.     }
  135.     size_type erase(const key_type& x) { 
  136.         return t.erase(x); 
  137.     }
  138.     void erase(iterator first, iterator last) { 
  139.         t.erase((typename rep_type::iterator&)first, 
  140.                 (typename rep_type::iterator&)last); 
  141.     }
  142.     void clear() { t.clear(); }
  143.  
  144. // multiset operations:
  145.  
  146.     iterator find(const key_type& x) const { return t.find(x); }
  147.     size_type count(const key_type& x) const { return t.count(x); }
  148.     iterator lower_bound(const key_type& x) const {
  149.         return t.lower_bound(x);
  150.     }
  151.     iterator upper_bound(const key_type& x) const {
  152.         return t.upper_bound(x); 
  153.     }
  154.     pair<iterator,iterator> equal_range(const key_type& x) const {
  155.         return t.equal_range(x);
  156.     }
  157.   friend bool operator==(const self&, const self&);
  158.   friend bool operator<(const self&, const self&);
  159. };
  160.  
  161. __END_STL_FULL_NAMESPACE
  162.  
  163. // do a cleanup
  164. #  undef multiset
  165. // provide a way to access full funclionality 
  166. #  define __multiset__  __FULL_NAME(multiset)
  167.  
  168. template <class Key, class Compare, class Alloc>
  169. inline bool operator==(const __multiset__<Key, Compare, Alloc>& x, 
  170.                        const __multiset__<Key, Compare, Alloc>& y) {
  171.   return x.t == y.t;
  172. }
  173.  
  174. template <class Key, class Compare, class Alloc>
  175. inline bool operator<(const __multiset__<Key, Compare, Alloc>& x, 
  176.                       const __multiset__<Key, Compare, Alloc>& y) {
  177.   return x.t < y.t;
  178. }
  179.  
  180. # if defined (__STL_CLASS_PARTIAL_SPECIALIZATION )
  181. template <class Key, class Compare, class Alloc>
  182. inline void swap(__multiset__<Key, Compare, Alloc>& a,
  183.                  __multiset__<Key, Compare, Alloc>& b) { a.swap(b); }
  184. # endif
  185.  
  186. # ifndef __STL_DEFAULT_TYPE_PARAM
  187. // provide a "default" multiset adaptor
  188. template <class Key, class Compare>
  189. class multiset : public __multiset__<Key, Compare, alloc>
  190. {
  191.     typedef multiset<Key,Compare> self;
  192. public:
  193.     typedef __multiset__<Key, Compare, alloc> super;
  194.     __CONTAINER_SUPER_TYPEDEFS
  195.     // copy & assignment from super
  196.     __IMPORT_SUPER_COPY_ASSIGNMENT(multiset)
  197.     explicit multiset() : super(Compare()) {}
  198.     explicit multiset(const Compare& comp) : super(comp) {}
  199.     multiset(const value_type* first, const value_type* last) : 
  200.         super(first, last, Compare()) { }
  201.     multiset(const value_type* first, const value_type* last, 
  202.         const Compare& comp) : super(first, last, comp) { }
  203.     multiset(const_iterator first, const_iterator last) : 
  204.         super(first, last, Compare()) { }
  205.     multiset(const_iterator first, const_iterator last, 
  206.         const Compare& comp) : super(first, last, comp) { }
  207. };
  208.  
  209. #  if defined (__STL_BASE_MATCH_BUG)   
  210. template <class Key, class Compare>
  211. inline bool operator==(const multiset<Key, Compare>& x, 
  212.                        const multiset<Key, Compare>& y) {
  213.   typedef __multiset__<Key,Compare,alloc> super;
  214.   return (const super&)x == (const super&)y;
  215. }
  216.  
  217. template <class Key, class Compare>
  218. inline bool operator<(const multiset<Key, Compare>& x, 
  219.                       const multiset<Key, Compare>& y) {
  220.   typedef __multiset__<Key,Compare,alloc> super;
  221.   return (const super&)x < (const super&)y;
  222. }
  223. #  endif
  224.  
  225. # endif /*  __STL_DEFAULT_TEMPLATE_PARAM */
  226.  
  227. __END_STL_NAMESPACE
  228.  
  229. #endif
  230.